﻿using System;
using System.Collections.Generic;
using tour.szhome.common;
using TOUR.SZHOME.DAL;
using TOUR.SZHOME.Entity;
namespace TOUR.SZHOME.BLL
{
    /// <summary>
    /// 数据表Projects_New的业务逻辑类
    /// </summary>
    public class Projects_NewBLL
    {
        /// <summary>
        /// 获取项目下的项目 -- 分页
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="pageSet"></param>
        /// <returns></returns>
        public List<Projects_NewEntity> GetNewsListByPID(int pid, PageSet pageSet)
        {
            string where = " XMID = " + pid;
            // 分页助手处理
            pageSet.RecordCount = Projects_NewDAL.SearchCount(where);
            pageSet.PageCount = (int)Math.Ceiling(pageSet.RecordCount / (pageSet.PageSize * 1.0));
            return Projects_NewDAL.Search(where, "XMID", (pageSet.PageIndex - 1) * pageSet.PageSize, pageSet.PageSize);
        }

        /// <summary>
        /// 根据ID删除对象
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public bool DelByID(int nid)
        {
            return Projects_NewDAL.Delete(nid);
        }

        /// <summary>
        /// 根据对象ID获取实体
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        public Projects_NewEntity GetNewsByID(int nid)
        {
            return Projects_NewDAL.GetByDTID(nid);
        }

        /// <summary>
        /// 编辑动态的逻辑方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool EditNews(Projects_NewEntity model)
        {
            if (model.DTID > 0)
            {
                return Projects_NewDAL.Update(model);
            }
            else
            {
                return Projects_NewDAL.Insert(model);
            }
        }
    }
}
